import Service from '../../core/baseService';

export default class CartService extends Service {
  constructor(ctx) {
    super(ctx);
    this.model = this.ctx.sassmodel.Cart;
  }

  async list(query) {
    const result: any = await this.model
      .findAndCountAll({
        where: query,
        include: [
          {
            model: this.ctx.model.Goods,
            attributes: [
              'name', 'nick', 'brief', 'main_pic', 'stock',
              'cost_price', 'market_price', 'price', 'id'
            ]
          }
        ],
        order: [['id', 'DESC']],
      });
    return {
      list: result.rows,
      total: result.count,
    }
  };

  async clear(user_id) {
    const result = await this.model.destroy({ where: { user_id } });

    return result;
  }


}
